import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useContractStore = defineStore('contract', () => {
  // 状态定义
  const currentContract = ref(null)
  const signingProgress = ref(0)
  const keyClauses = ref([])

  // 行业模板配置
  const templates = {
    manufacture: {
      title: '制造业入驻协议',
      clauses: ['生产安全规范条款', '产能保证条款', '环保责任条款']
    },
    logistics: {
      title: '物流业合作协议',
      clauses: ['运输时效保证条款', '货损赔偿条款', '仓储管理条款']
    }
  }

  // 异步操作
  const loadTemplate = async (category) => {
    currentContract.value = templates[category]
    keyClauses.value = currentContract.value.clauses
  }

  // 提交合同
  const submitContract = async (formData) => {
    // 实际应调用API接口
    console.log('Submitting contract:', formData)
    return new Promise((resolve) => {
      setTimeout(() => resolve({ success: true }), 1000)
    })
  }

  return {
    currentContract,
    signingProgress,
    keyClauses,
    loadTemplate,
    submitContract
  }
})
